// ==============================================================================================
// ItemBase.cs
//
// Created by: NI, 2007.03.27
// Revised by: NI, 2007.11.23
// ==============================================================================================
namespace RibbonExplorer.Entities
{
  // ==============================================================================================
  /// <summary>
  /// This class is intended to be the base class of all entity classes representing items.
  /// </summary>
  // ==============================================================================================
  public abstract class ItemBase
  {
    #region Private fields

    private readonly string _Id;
    protected bool _ChildrenLoaded;

    #endregion

    #region Lifecycle methods

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Creates an item instance with the specified ID.
    /// </summary>
    /// <param name="id">Office application ID</param>
    // --------------------------------------------------------------------------------------------
    public ItemBase(string id)
    {
      _Id = id;
      _ChildrenLoaded = false;
    }

    #endregion

    #region Public properties

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Gets the ID of the item
    /// </summary>
    // --------------------------------------------------------------------------------------------
    public string Id
    {
      get { return _Id; }
    }

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Gets the flag indicating if item's children has been loaded or not.
    /// </summary>
    // --------------------------------------------------------------------------------------------
    public bool ChildrenLoaded
    {
      get { return _ChildrenLoaded; }
    }

    #endregion

    #region Public methods

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Loads the children of this item, if not already loaded.
    /// </summary>
    // --------------------------------------------------------------------------------------------
    public void LoadChildren()
    {
      if (!_ChildrenLoaded)
      {
        OnLoadChildren();
        _ChildrenLoaded = true;
      }
    }

    #endregion

    #region Protected virtual methods

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Override this method to load the children of this item.
    /// </summary>
    // --------------------------------------------------------------------------------------------
    protected virtual void OnLoadChildren()
    {
    }

    #endregion
  }
}